package com.cc;

import com.cc.config.SpringConfig;
import com.cc.entity.Product;
import com.cc.mapper.ProductMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class productMapper {

    @Autowired
    ProductMapper productMapper;

    @Test
    public void testAddProduct() {
        Product pd = new Product();
        pd.setProductName("测试");
        pd.setBrandId(1);
        pd.setCategoryId(1);
        pd.setCurrency("CNY");
        pd.setDescription("描述");
        pd.setImageUrl("");
        pd.setPrice(100);
        pd.setStatus("1");
        pd.setStockQuantity(100);
        int result = productMapper.addProduct(pd);
        System.out.println(result);
    }
    @Test
    public void testDeleteProductsById() {
        int result = productMapper.deleteProductById(13);
        System.out.println(result);
    }
    @Test
    public void testFindProductsById() {
        Product product = productMapper.findProductById(2);
        System.out.println(product);
    }
    @Test
    public void testGetAllProducts() {
        List<Product> products = productMapper.getAllProduct();
        for (Product product : products) {
            System.out.println(product);
        }
    }
    @Test
    public void testUpdateProducts() {
        Product product = new Product();
        product.setProductId(1);
        product.setProductName("测试");
        product.setBrandId(1);
        product.setCategoryId(1);
        product.setCurrency("CNY");
        product.setDescription("描述");
        product.setImageUrl("");
        product.setPrice(100);
        product.setStatus("1");
        product.setStockQuantity(100);
        int result= productMapper.updateProduct(product);
        System.out.println(result);
    }
}
